package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.AffixFactory.BuffTypeEnum;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.data.bean.skill;

import java.util.ArrayList;
import java.util.Collections;

/** 混乱 */
@BuffType(Type = BuffTypeEnum.混乱)
public class Affix_57_混乱 extends Buff {

	public Affix_57_混乱(Fighter source, Fighter target, skill skilldata, int[] params) {
		super(source, target, skilldata, params);
	}

	@Override
	public boolean exec(Fighter source, Fighter actor) {
		// 随机一个活人当作目标
		ArrayList<Fighter> list = new ArrayList<>();
		for (Fighter fighter : actor.getTeam().getFighters()) {
			if (fighter.is活着() && !fighter.equals(actor)) {
				list.add(fighter);
			}
		}
		Collections.shuffle(list);

		if(list.size()>0){
			Fighter 倒霉蛋 = list.get(0);
			getAffixContext().get攻击行动().clear目标们();
			getAffixContext().get攻击行动().addTarget(倒霉蛋);
			getAffixContext().set跳过怒气技能(true);
			Battle.battleLogger(6,"混乱"+source.getName()+"普通攻击"+倒霉蛋.getName());
		}else{
			getAffixContext().get攻击行动().clear目标们();
			getAffixContext().set跳过普通技能(true);
			getAffixContext().set跳过怒气技能(true);
			Battle.battleLogger(6,"混乱"+source.getName()+"找不到人，只能不攻击");
		}

		return true;
	}

	@Override
	public BuffType getBuffType() {
		return BuffType.控制效果;
	}

	@Override
	public BuffStateType getBuffStateType() {
		return BuffStateType.混乱状态;
	}
}